package assignment1;


public class MainUI {

   private static final int Just_One_Cycle = 1;

   private ProjectModel pmodel;
    private GridView gview;

   public MainUI(){
       pmodel = new ProjectModel();
       gview = new GridView (this.pmodel);

   }

   public void showMenu(){
    /*
       === MENU ===
1. Set Number of horizontal lanes (H-street) [min 1, max 3]
2. Set Number of vertical lanes  (V-street) [min 1, max 4]
3. Set Probability of a car entering H-street [min 0, max 1]
3. Set Probability of a car entering V-street [min 0, max 1]
5. Run one simulation cycle
6. Set and run number of simulation cycles [min 1, max 10]
Enter your choice>   */

while(true){
    gview.initialGrid('?');
    gview.showGrid();
    System.out.print("=== MENU === \n" +
    " 1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n "+
    " 2. Set Number of vertical lanes  (V-street) [min 1, max 4]\n "+
    " 3. Set Probability of a car entering H-street [min 0, max 1]\n "+
    " 4. Set Probability of a car entering V-street [min 0, max 1]\n "+
    " 5. Run one simulation cycle\n "+
    " 6. Set and run number of simulation cycles [min 1, max 10]\n "+
    " ");
    String uChoice = GetUserInput.getUChoice("Enter your choice>");
    int uChoiceInt = Integer.parseInt(uChoice);
    System.out.println("After int conversion" + uChoiceInt);
    // display command line menu

    switch(uChoiceInt){
        case 1: System.out.println("Menu 1");
                setNumHortLanes();
                break;
        case 2: System.out.println("Menu 2");
                setNumVertLanes();
                break;
        case 3: System.out.println("Menu 3");
                setProbHStreet();
                break;
        case 4: System.out.println("Menu 4");
                setProbVStreet();
                break;
        case 5: System.out.println("Menu 5");
                gview.moveCars(Just_One_Cycle);
                break;
        case 6: System.out.println("Menu 6");
                String simNum = GetUserInput.getUChoice("How many simulation Cycles? >");
                int simulaNum = Integer.parseInt(simNum);
            int lowerLimit = 1;
            int upperLimit = 10;
            if(simulaNum <= upperLimit && simulaNum >= lowerLimit ){
              gview.moveCars(simulaNum);
                
            }else{
                System.out.println("Error In Entering Horizlanes");
                System.out.println("Plears Enter Number Above 1 and Below 10. ");
            }              
                break;
        default: System.out.println("Error in Entering Menu Choice");
                break;
    }
        }
    }

   public void setNumHortLanes(){
       String uChoice = GetUserInput.getUChoice ("Enter number of Horizlanes: ");
       int uChoiceInt = Integer.parseInt(uChoice);
       int lowerLimit = 1;
       int upperLimit = 3;
       if (uChoiceInt > upperLimit || uChoiceInt < lowerLimit){
           System.out.println("Error In Entering Horizlanes");
           System.out.println("Please Enter Number Above 1 and Below 3. ");
           showMenu();
       }else {
           pmodel.setHortLanes(uChoiceInt);
           pmodel.getHortLanes();
       }
   }//  end of menu one

        public void setNumVertLanes(){
            String uChoice = GetUserInput.getUChoice("Enter Number of Vertlanes: ");
            int uChoiceInt = Integer.parseInt(uChoice);
            int lowerLimit = 1;
            int upperLimit = 4;
            if(uChoiceInt > upperLimit || uChoiceInt < lowerLimit){
                System.out.println("Error In Entering Horizlanes");
                System.out.println("Plears Enter Number Above 1 and Below 3. ");
                showMenu();
            }else{
                pmodel.setVertLanes(uChoiceInt);
                pmodel.getVertLanes();
            }
        }//end of menu two


        private void setProbHStreet(){
            String uChoice = GetUserInput.getUChoice("Enter Probability of a car H-Street ");
            float uChoiceInt = Float.valueOf(uChoice.trim()).floatValue();
            float lowerLimit = 0.0f;
            float upperLimit = 1.0f;
            if (uChoiceInt > upperLimit || uChoiceInt < lowerLimit){
                System.out.println("Error in entering Horizontal Input ");
                System.out.println("Please Enter Probility Number Above 0 and Below 1");
                showMenu();
            }else{
                pmodel.setHortProba(uChoiceInt);
                pmodel.getHortProbl();
            }
        }// end of menu three

        public void setProbVStreet(){
            String uChoice = GetUserInput.getUChoice("Enter Probability of a car V-Street");
            float uChoiceInt = Float.valueOf(uChoice.trim()).floatValue();
            float lowerLimit = 0.0f;
            float upperLimit = 1.0f;
            if (uChoiceInt > upperLimit || uChoiceInt < lowerLimit){
                System.out.println("Error in entering Vertical Input ");
                System.out.println("Please Enter Probility Number Above 0 and Below 1");
                showMenu();
            }else{
                pmodel.setVertProba(uChoiceInt);
                pmodel.getVertProbl();
        }
    }//end of menu four

        public float showVertProba(){
            return pmodel.getVertProbl();
        }
        public float showHortProba(){
            return pmodel.getHortProbl();
        }
        public int showHortLanes(){
            return pmodel.getHortLanes();
        }
        public int showVertLanes(){
            return pmodel.getVertLanes();
    }
}

